import React from 'react';
import ReactDOM from 'react-dom';

import {createHashHistory} from 'history';

import {Router, Route, useRouterHistory} from 'react-router'

import {syncHistoryWithStore,RouterStore} from 'mobx-react-router';

import {Provider} from 'mobx-react';

import Workplan from 'weaWorkplan' //umd
// import ComMobx from 'comsMobx'
//import Workplan from './index'

import {WeaLocaleProvider} from 'ecCom';

const getLocaleLabel = WeaLocaleProvider.getLocaleLabel.bind(this, 'workplan');
const { getLocaleLabelByCode } = WeaLocaleProvider;

// const allStore = Workplan.store;
const routing = new RouterStore();


const allStore = {
    routing,
    ...Workplan.store,
    // ...ComMobx.store,
}

// allStore.routing = routing;
const WpRoute = Workplan.Route;

const browserHistory = useRouterHistory(createHashHistory)({
  queryKey: '_key',
  basename: '/'
});

const history = syncHistoryWithStore(browserHistory, allStore.routing);

class Home extends React.Component {
  render() {
    return this.props.children;
  }
}

class Root extends React.Component {
  componentDidMount() {
    // 多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('workplan').then(() => { 
      this.setState({ reRender: true }); 
    });
  }

  render() {
    return (
      <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@wsfs4r`} {...allStore}>
        <Router ecId={`${this && this.props && this.props.ecId || ''}_Router@0a4x8y`} history={history}>
          <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ed5gg1`} name="main" breadcrumbName="入口" path="/main" component={Home} onEnter={getLocaleLabel}>
            {WpRoute}
          </Route>
        </Router>
      </Provider>
    )
  }
}

ReactDOM.render(<Root ecId={`${this && this.props && this.props.ecId || ''}_Root@lvkt83`}/>, document.getElementById('container'));

module.exports=Workplan;